package com.ywk.json;


import com.ywk.json.core.impl.OutPutHandler1;
import com.ywk.json.core.impl.OutPutHandler2;
import com.ywk.json.core.impl.OutPutHandler3;
import com.ywk.json.process.JsonProcess;

/**
 * @author zbh
 * @date 2022/3/8 16:36
 */
public class JsonMain {
    public static void main(String[] args) {
        //获取user.json输入流
        String path = ClassLoader.getSystemResource("json/user.json").getPath().substring(1);//省略磁盘前面的“/”
//        System.out.println(path);
        //解析json文件
        JsonProcess jsonProcess=new JsonProcess();
        jsonProcess.parse(path);

        OutPutHandler1 outPutHandler1 = new OutPutHandler1();
        OutPutHandler2 outPutHandler2 = new OutPutHandler2();
        OutPutHandler3 outPutHandler3 = new OutPutHandler3();
        jsonProcess.addOutPutHandler(outPutHandler1).addOutPutHandler(outPutHandler2).addOutPutHandler(outPutHandler3);


        //输出三种格式文件
        jsonProcess.outPut();



        /*String path = Thread.currentThread().getContextClassLoader().getResource("json/user.json").getPath();
        StringBuffer jsonStr=new StringBuffer();


        FileInputStream fis=null;
        InputStreamReader isr=null;
        BufferedReader br=null;
        try {
            fis=new FileInputStream(path);
            isr=new InputStreamReader(fis);
            br=new BufferedReader(isr);
            String line = "";
            while((line = br.readLine()) != null){
                jsonStr.append(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (isr != null) {
                try {
                    isr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        //获取json格式（数组或对象）
        JSONArray jsonArray = JSONObject.parseArray(jsonStr.toString());
        User user = JSON.toJavaObject(jsonArray.getJSONObject(0), User.class);
        System.out.println(user);
        System.out.println(jsonArray);*/

    }
}

